const { RecurrenceRule } = require('node-schedule');
var DbCommon = require('./db');
var Timer = require('./timer');

module.exports = {
	refreshAlltime: function () {
		const sqlOptions = {
	        limit: 0,
	        offset: 0,
	        wheres: [{"type":"1","key":"status","value":1}],
	        like: "",
	        order: "id",
	        table: "article"
	   	};
	    DbCommon.refreshDataList(sqlOptions).then(function (data) {
			console.log('刷新定时器查询article返回data',data);
	        var returnData = {
	            totleNumb: data[0][0].totleNumb,
	            dataList: data[1]
			};
			console.log('添加定时器文章列表',returnData.dataList);
			// 异动文章id列表
			var changeList = [33,34,35,36,37,38,43,44,45];
	        returnData.dataList.forEach(item => {
			// 个股异动涨停、个股异动跌停、个股异动上涨、个股异动下跌、板块异动涨停、板块异动跌停、个股文章揭秘由接口触发，非定时触发，由接口触发
			if(changeList.indexOf(item.id) !== -1 ) return;
			Timer.startSchedule(item.publish_time, item.id);
	        })
	    }, function (error) {
	        console.log(error)
	    });
    }
}